<?php
if (!defined('IN_WONDERSHARE'))
{
die('Hacking attempt');
}
require('./classes/module/module_product_mobile.php');
class ProductOperationControl
{
	var $product_operation_m;
	function __construct()
	{
		$this->product_operation_m = new ProductOperationModule();
	}
	/**
	* 增加或修改商品
	*
	* @param   string     $type                       类型 （add为增加商品， update为修改商品）
	* @param   int        $product_cbsid              cbs产品ID
	* @param   int        $product_sn                 产品编号
	* @param   string     $product_name               产品名称
	* @param   int        $product_version            版本号
	* @param   int        $product_brand              品牌
	* @param   int        $product_os                 存储平台表ID
	* @param   string     $product_isfree             是否免费
	* @param   string     $product_is_year_charge     是否按年收费（0否，1是）
	* @param   string     $product_type               是否试用
	* @param   string     $product_rel   			          对应产品
	* @param   string     $product_icon_min           Icon图标-小
	* @param   string     $product_icon_max           Icon图标-大
	* @param   string     $product_box_min            Box盒子图-小
	* @param   string     $product_box_middle   	    Box盒子图-中
	* @param   string     $product_box_big            Box盒子图-大
	* @param   int        $product_video_promo        Promo Demo URL
	* @param   int        $product_ad                 产品标语(广告语)
	* @param   string     $product_intro              产品简介（短描述）
	* @param   int        $product_content            产品简介（长描述
	* @param   int        $product_key_feature        产品Key Feature点
	* @param   int        $product_support_intro      系统支持说明-简单
	* @param   string     $product_support_content    系统支持说明-完整
	* @param   string     $techspec_content_table     技术参数表单
	* @param   string     $product_guide_content      guide详细内容
	* @param   string     $video_url                  视频url地址
	* @param   int        $video_width                视频宽
	* @param   int        $video_higth                视频高
	* @return  int
	*/
	
	function  change_product(array $array)
	{
		if($array[type] == 'add')
		{
			$sql_num = "SELECT `id` FROM mobile_product WHERE product_id = ".$array['hidden_products_id']." AND  m_product_delete = 0";
			$query = $GLOBALS['db']->query($sql_num);
			$num =  $GLOBALS['db']->num_rows($query);
			if($num == 0)
			{
				$sql ="INSERT INTO mobile_product (product_id ,cat_id,pic_url1,pic_url2 ,pic_url3,tag,m_product_recomm,m_product_intro,m_product_content,
				m_product_support_intro,m_product_support_content,m_product_add_user ,m_product_add_time,box_url) VALUES ('$array[hidden_products_id]',
				'$array[parent_id]','$array[pic_url1]','$array[pic_url2]','$array[pic_url3]','$array[tag]','$array[h_m_product_recomm]','$array[m_product_intro]', '$array[m_product_content]',
				'$array[m_product_support_intro]','$array[m_product_support_content]','".$_SESSION['AName']."','".$_SERVER['REQUEST_TIME']."','".$_SERVER['box_url']."') ";
				//die($sql);
			}else
			{
				return -1;
			}
		
		}elseif($array[type] == 'update')
		{
			$sql = "UPDATE  mobile_product  SET cat_id = '$array[parent_id]',pic_url1 = '$array[pic_url1]' ,pic_url2 = 
			'$array[pic_url2]',pic_url3 = 
			'$array[pic_url3]',box_url='$array[box_url]',tag = '$array[tag]',m_product_recomm = '$array[h_m_product_recomm]',m_product_intro = '$array[m_product_intro]'
			,m_product_content = '$array[m_product_content]',m_product_support_intro = '$array[m_product_support_intro]',
			m_product_support_content = '$array[m_product_support_content]', m_product_update_time = '".$_SERVER['REQUEST_TIME']."',m_product_update_user = '".
			$_SESSION['AName']."',modify_status = 1 WHERE   id  = '$array[product_id]'  ";
			//die($sql);
			
			return $this->product_operation_m->change_info($sql);
		}
		
		return $this->product_operation_m->get_insert_id($sql);		
	}

	/**
	* 增加feature 
	*
	* @param   string     $insert_str              cbs产品ID
	* @param   int        $product_id              产品id
	* @param   string     $type                    类型 （insert为增加feature ， m_insert为增加更多feature）
	* @return  int
	*/
	function  insert_feature_info($insert_str,$product_id,$type)
	{
		if($type == 'insert')
		{
			$sql ="INSERT INTO mobile_feature  (product_id  ,feature_title  ,feature_pic_min ,feature_pic_max 
			,feature_intro,feature_type ,feature_order ,add_time , add_user )  VALUES $insert_str ";
		}elseif($type == 'm_insert')
		{
			$sql ="INSERT INTO mobile_feature  (product_id  ,feature_title  ,more_feature_pic
			,feature_intro,feature_type ,feature_order ,add_time , add_user )  VALUES $insert_str ";
		}
		//die($sql);
		return $this->product_operation_m->change_info($sql);
	}

	/**
	* 得到产品信息
	* @param   int        $product_id              产品id
	* @return  array
	*/
	function get_product_info($type,$public_product_id = 0,$product_id = 0)
	{
		if ($type == 'get_name')
		{
			$sql = "SELECT  product.product_name   FROM mobile_product AS won_p  LEFT JOIN product AS product 
			ON won_p.product_id =  product.product_id   WHERE won_p.id = $product_id  AND  won_p.m_product_delete = 0";
		}
		elseif($type == 'edit')
		{
			$date_info = $attributes = $date_page = array();
			$sql = 'SELECT product.product_name,m.id,m.cat_id,m.m_product_recomm,m.tag,m.pic_url1,m.pic_url2,m.pic_url3,m.box_url
			,m.m_product_intro,m.sort,m.m_product_content,m.m_product_support_intro
			FROM mobile_product as m LEFT JOIN product as product ON m.product_id =product.product_id
			WHERE  m.id  = '.$product_id;
			$date_info =  $this->product_operation_m->get_product_info($sql);
			//下面代码是根据id取名称
			if(!empty($date_info[0]['m_product_recomm']))
			{
				$recommended_str = '';
				$recommended_products = explode(',',$date_info[0]['m_product_recomm']);
				for($k = 0 ;$k<count($recommended_products);$k++)
				{
					$recommended_date =  $this->get_product_info('get_name',0,$recommended_products[$k]);
					
					$recommended_str = $recommended_str.','.$recommended_date[0]['product_name'];
				}
				unset($recommended_products);unset($recommended_date);
			}
			$date_info[0]['recommended_name'] = substr($recommended_str,1);
			
			//上面代码是根据id取名称
			return $date_info;
		}
		return $this->product_operation_m->get_product_info($sql);
	}
	/**
	* 得到feature
	* @param   int        $product_id              产品id
	* @param   string     $type                    类型
	* @return  array
	*/
	function get_feature_info($product_id,$type)
	{
		if($type == 'feature')
		{
			$sql = "SELECT product_id ,feature_id ,feature_title ,feature_intro ,feature_pic_min ,
			feature_pic_max,feature_order  FROM mobile_feature  WHERE product_id  = $product_id  AND feature_type  = 0 
			AND is_delete  =  0  ORDER BY feature_order ASC ";
		}elseif($type == 'm_feature')
		{
			$sql = "SELECT product_id ,feature_id ,feature_title ,feature_intro ,more_feature_pic ,feature_order 
			FROM mobile_feature  WHERE product_id  = $product_id  AND feature_type  = 1 AND is_delete  =  0  ORDER BY feature_order ASC ";
		}
		//die($sql);
		return $this->product_operation_m->get_product_info($sql);
	}
	/**
	* 修改feature
	* @param   string        $type               类型 
	* @param   int        $feature_id           特点id
	* @param   int        $feature_intro        特点描述
	* @param   string     $feature_title        特点标题
	* @param   string     $more_feature_pic     更多配图
	* @param   string     $feature_pic_min      特点小图
	* @param   string     $feature_pic_max      特点大图
	* @return  int
	*/
	function  update_feature_info($type,$feature_id,$feature_intro = '',$feature_title = '',$more_feature_pic = '' ,
	$feature_pic_min = ''  ,$feature_pic_max = '')
	{
		if($type == 'feature')
		{
			$sql = "UPDATE mobile_feature  SET feature_title = '".$feature_title."',feature_intro  = '".$feature_intro."' ,
			feature_title = '".$feature_title."',feature_pic_min  = '".$feature_pic_min ."',modify_status = 1,
			feature_pic_max  = '".$feature_pic_max ."' , update_time = '".$_SERVER['REQUEST_TIME']."' ,
			update_user  =  '".$_SESSION['AName']."'  WHERE feature_id  = '".$feature_id."' ";
		}elseif($type == 'more_feature')
			{
			$sql = "UPDATE mobile_feature  SET feature_title = '".$feature_title."',feature_intro  = '".$feature_intro ."' ,
			feature_title = '".$feature_title."',more_feature_pic   = '".$more_feature_pic ."', update_time = 
			'".$_SERVER['REQUEST_TIME']."' ,modify_status = 1,update_user  =  '".$_SESSION['AName']."'  WHERE
			feature_id  = '".$feature_id."' ";
		}elseif($type = 'delete')
		{
			$sql =  'UPDATE feature SET is_delete  = 1  WHERE feature_id = '.$feature_id;	
		}
		//die($sql);
		return $this->product_operation_m->change_info($sql);
	}


}
?>